package com.neuedu.hisadmin.controller;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.neuedu.hisadmin.dto.Result;
import com.neuedu.hisadmin.entity.Customer;
import com.neuedu.hisadmin.service.ICheckapplyService;
import com.neuedu.hisadmin.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jaun
 * @since 2025-07-05
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    //Controller 调用Service,service调用Mapper

    @Autowired
    private ICustomerService customerService;

    /*
  返回所有注册用户信息
  后续所有返回都使用Result<T>进行包装
  Result<int> 返回1
  Result<String>返回字符串
   */
    @GetMapping("/list")
    public Result<List<Customer>> getCustomers() {
        List<Customer> customers = customerService.list();
        return Result.success(customers);
    }

    @GetMapping("/{id}")
    public Result<Customer> getCustomerById(@PathVariable("id") Integer customerId) {
        Customer customer = customerService.getById(customerId);
        if (customer == null) {
            return Result.error(500, "没有对应用户");
        }
        return Result.success(customer);
    }

    @RequestMapping("/find")
    public Result<List<Customer>> getCustomerByCon(@RequestParam (required = false)String name, @RequestParam(required = false) String number) {
        if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(number)) {
              return Result.error(500,"请输入查询参数");
        }
        List<Customer> customers = customerService.getCustomerByNameOrNumber(name, number);
        return Result.success(customers);
    }
}
